/**
 * @Description: 用户接口管理
 * @Author: Zander
 * @Date: 2023/1/31 10:52
 * @LastEditors: Zander
 * @LastEditTime: 2023/1/31 10:52
 */
import { $get, $post } from '../utils';
import { ehsPhoneApi, sysApi } from '@/config/prefix';

/**
 * 登录
 * @param {object} loginParams
 * @returns {Promise<minimist.Opts.unknown>}
 */
export const apiLogin = (loginParams) => $post({
  url: `${sysApi}/ext/api/appLogin`,
  headers: {
    'Content-Type': 'application/json;charset=UTF-8',
    'h-rKey': loginParams.rkey,
    'h-iv': loginParams.iv
  },
  data: { loginName: loginParams.loginName, password: loginParams.password, openid: loginParams.openid, userType: loginParams.userType }
})

/**
 * 通过token登录
 * @returns {Promise<minimist.Opts.unknown>}
 */
export const apiLoginByToken = () => $post({
  url: `${sysApi}/cadeUser/loginByToken`
})

/**
 * 通过 Openid 登录
 * @param {object} loginParams
 * @returns {Promise<minimist.Opts.unknown>}
 */
export const apiLoginByOpenid = (loginParams) => $post({
  url: `${sysApi}/ext/api/loginByOpenid`,
  data: loginParams
})

/**
 * 通过 Openid 登录
 * @param {object} loginParams
 * @returns {Promise<minimist.Opts.unknown>}
 */
export const apiAppLoginByOpenid = (loginParams) => $post({
  url: `${sysApi}/ext/api/appLoginByOpenid`,
  data: loginParams
})

/**
 * 用户 openid 解绑
 * @returns {Promise<minimist.Opts.unknown>}
 */
export const unBindOpenid = () => $post({
  url: `${sysApi}/ext/api/unBindOpenid`
})

/**
 * 登出
 */
export const apiLogOut = () => $post({
  url: `${sysApi}/cadeUser/logOut`
});

/**
 * 分页查询
 */
export const getSession = (code) => $get({
  url: '/wechat/ma/getSession',
  params: { code }
});

/**
 * 修改密码
 * @param passwordParams
 * @returns {Promise<minimist.Opts.unknown>}
 */
export const apiUpdatePassword = (passwordParams) => $post({
  url: `${sysApi}/cadeUser/updateUserPwd`,
  data: passwordParams
});

/**
 * 分页查询
 */
export const apiUserSearch = (searchParams) => $get({
  url: `${sysApi}/cadeUser/search`,
  params: searchParams
});

/**
 * 根据ID获取详情
 */
export const apiUserGetById = (id) => $get({
  url: `${sysApi}/cadeUser/getById`,
  params: { id: id }
});

/**
 * 保存信息
 */
export const apiUserSave = (saveParams) => $post({
  url: `${sysApi}/cadeUser/save`,
  data: saveParams
});

/**
 * 更新信息
 */
export const apiUserUpdateById = (updateParams) => $post({
  url: `${sysApi}/cadeUser/updateById`,
  data: updateParams
});

/**
 * 根据ID删除信息
 */
export const apiUserDeleteById = (id) => $post({
  url: `${sysApi}/cadeUser/deleteById`,
  data: { id: id }
});

/**
 * 批量删除信息
 */
export const apiUserBatchDeleteByIds = (ids) => $post({
  url: `${sysApi}/cadeUser/batchDeleteByIds`,
  data: { ids: ids }
});

/**
 * 根据ID逻辑删除信息
 */
export const apiUserLogicDeleteById = (id) => $post({
  url: `${sysApi}/cadeUser/logicDeleteById`,
  data: { id: id }
});

/**
 * 批量逻辑删除
 */
export const apiUserLogicBatchDeleteByIds = (ids) => $post({
  url: `${sysApi}/cadeUser/logicBatchDeleteByIds`,
  data: { ids: ids }
});

/**
 * 无权限控制
 * 分页查询用户
 */
export const apiSearchUsers = (searchParams) => $get({
  url: `${sysApi}/cadeUser/searchUsers`,
  params: searchParams
});

/**
 * 分页查询角色待选择用户
 * @param searchParams
 */
export const apiSearchRoleSelectUsers = (searchParams) => $get({
  url: `${sysApi}/cadeUser/searchRoleSelectUsers`,
  params: searchParams
});

/**
 * 分页查询角色用户
 * @param searchParams
 */
export const apiSearchRoleUsers = (searchParams) => $get({
  url: `${sysApi}/cadeUser/searchRoleUsers`,
  params: searchParams
});

/**
 * 重置密码
 * @param params
 */
export const apiUpdateCurrentPwd = (params) => $post({
  url: `${sysApi}/cadeUser/updateCurrentPwd`,
  data: params
});

/**
 * 保存用户角色
 * @param params
 */
export const apiSaveUserRole = (params) => $post({
  url: `${sysApi}/cadeUser/saveUserRole`,
  data: params
});

/**
 * 修改用户组织机构
 * @param params
 */
export const grantOrganization = (params) => $post({
  url: `${sysApi}/cadeUser/grantOrganization`,
  data: params
});
/**
 * 统一openid登录
 * @param loginParams
 */
export const loginByOpenid = (loginParams) => $post({
  url: `${sysApi}/cadeUser/loginByOpenid`,
  data: loginParams
});
/**
 * 是否已存在人员用户
 * @param params
 */
export const authByOpenid = (params) => $post({
  url: `${ehsPhoneApi}/parkPerson/authByOpenid`,
  data: params
});
/**
 * 获取身份证
 * @param params
 */
export const getByIdCardNo = (params) => $get({
  url: `${ehsPhoneApi}/parkPerson/getByIdCardNo`,
  data: params
});
/**
 * 工作人员进行登录
 * @param params
 */
export const parkPersonLogin = (params) => $post({
  url: `${ehsPhoneApi}/parkPerson/login`,
  data: params
});
/**
 * 仓库、门卫、承运商进行信息绑定
 * @param params
 */
export const bindOpenid = (params) => $post({
  url: `${ehsPhoneApi}/parkPerson/bindOpenid`,
  data: params
});
/**
 * 访客登录
 * @param params
 * @returns {Promise<*>}
 */
export const visitorAuthByOpenid = (params) => $post({
  url: `${ehsPhoneApi}/visitor/authByOpenid`,
  data: params
});
